import axios from "@/axios"

// 获取分类总数
export function getCategoryCount() {
    // 修改为使用列表接口，使用POST请求代替GET
    return axios.post("/admin/category/list", { current: 1, size: 1 })
        .then(response => {
            if (response && response.success && response.data && response.data.total) {
                return {
                    success: true,
                    data: response.data.total
                };
            }
            return {
                success: false,
                data: 0
            };
        })
        .catch(error => {
            console.error("获取分类数量失败:", error);
            return {
                success: false,
                data: 0
            };
        });
}

// 获取标签总数
export function getTagCount() {
    // 修改为使用列表接口，使用POST请求代替GET
    return axios.post("/admin/tag/list", { current: 1, size: 1 })
        .then(response => {
            if (response && response.success && response.data && response.data.total) {
                return {
                    success: true,
                    data: response.data.total
                };
            }
            return {
                success: false,
                data: 0
            };
        })
        .catch(error => {
            console.error("获取标签数量失败:", error);
            return {
                success: false,
                data: 0
            };
        });
}

export function getDashboardArticleStatisticsInfo() {
    // 获取真实的文章数、分类数、标签数
    return Promise.all([
        axios.post("/admin/article/list", { current: 1, size: 1 }),
        axios.post("/admin/category/list", { current: 1, size: 999 }),
        axios.post("/admin/tag/list", { current: 1, size: 1 })
    ]).then(([articleRes, categoryRes, tagRes]) => {
        console.log('文章返回数据:', articleRes);
        console.log('分类返回数据:', categoryRes);
        console.log('标签返回数据:', tagRes);
        
        // 添加更详细的日志
        console.log('文章总数:', articleRes.data?.data?.total);
        console.log('分类总数:', categoryRes.data?.data?.length);
        console.log('标签总数:', tagRes.data?.data?.total);
        
        return {
            success: true,
            data: {
                articleTotalCount: articleRes.data.total || 0,
                categoryTotalCount: categoryRes.data.length || 0,
                tagTotalCount: tagRes.data.total || 0,
                pvTotalCount: 1234  // 模拟数据
            }
        }
    });
}

export function getDashboardPublishArticleStatisticsInfo() {
    // 返回模拟数据
    return Promise.resolve({
        data: {
            data: {
                "2024-01": 5,
                "2024-02": 3,
                "2024-03": 8,
                "2024-04": 4,
                "2024-05": 6,
                "2024-06": 2
            }
        },
        errorCode: 20000,
        message: 'success',
        success: true
    });
}

export function getDashboardPVStatisticsInfo() {
    // 返回模拟数据
    return Promise.resolve({
        data: {
            data: {
                pvDates: ["03-23", "03-24", "03-25", "03-26", "03-27", "03-28", "03-29"],
                pvCounts: [120, 150, 180, 200, 160, 140, 190]
            }
        },
        errorCode: 20000,
        message: 'success',
        success: true
    });
}


